package redis;

import lombok.Cleanup;
import redis.clients.jedis.*;

import java.util.Arrays;

/**
 * @author 黄乾坤
 * @create 2022-08-24 15:49
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(20);
        jedisPoolConfig.setMaxIdle(10);
        jedisPoolConfig.setMinIdle(5);
//        JedisPool jedisPool = new JedisPool(jedisPoolConfig, "r-2jd20d1e0abeef34.redis.rds.aliyuncs.com", 6379, 3000, "Hiwi826@21Ng", 7);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, "192.168.236.128", 6379, 3000, null, 7);

        //从redis连接池里拿出一个连接执行命令
        @Cleanup Jedis jedis = jedisPool.getResource();
        String key = "test1xxxxx";

        jedis.set(key, "test");
        jedis.expire(key, 3);

        String s = jedis.get(key);
        System.out.println(s);

        Thread.sleep(3000);

        s = jedis.get(key);
        System.out.println(s);
        jedis.close();
    }
}
